const express = ("express")
var multer = require('multer');
const path = require("path");

let uploads= {
    multerUser() {
        var storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, 'F:/BiShe/Node/uploads/users')
            },
            filename: function (req, file, cb) {
                let extname = path.extname(file.originalname)
                cb(null, file.fieldname + '-' + Date.now() +  extname)
            }
        })
        var upload = multer({ storage: storage })
        return upload;
    },
    multerWriter() {
        var storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, 'F:/BiShe/Node/uploads/writers')
            },
            filename: function (req, file, cb) {
                let extname = path.extname(file.originalname)
                cb(null, file.fieldname + '-' + Date.now() + extname)
            }
        })
        var upload = multer({ storage: storage })
        return upload;
    },
    multerHome() {
        var storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, 'F:/BiShe/Node/uploads/home')
            },
            filename: function (req, file, cb) {
                let extname = path.extname(file.originalname)
                cb(null, file.fieldname + '-' + Date.now() + extname)
            }
        })
        var upload = multer({ storage: storage })
        return upload;
    },
    multerBook() {
        var storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, 'F:/BiShe/Node/uploads/book')
            },
            filename: function (req, file, cb) {
                let extname = path.extname(file.originalname)
                cb(null, file.fieldname + '-' + Date.now() + extname)
            }
        })
        var upload = multer({ storage: storage })
        return upload;
    }
}



//var upload = multer({ dest: 'upload/users' })
// router.post('/', upload.single('avatar'), (req, res) => {
//     res.json({
//         body: req.body,
//         file: req.file
//     })
// })

module.exports = uploads;